package com.gcb.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 证书等级
 */
@Getter
public enum CredentialsLevelEnum {
    FIRST(1, "一等"),
    SECOND(2, "二等"),
    THIRD(3, "三等"),
    FOURTH(4, "四等");

    private final Integer code;
    private final String info;

    CredentialsLevelEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }

    public static String getInfo(String type) {
        return Optional.ofNullable(of(Integer.valueOf(type)))
                .map(CredentialsLevelEnum::getInfo)
                .orElse("");
    }

    public static String getInfo(Integer type) {
        return Optional.ofNullable(of(type))
                .map(CredentialsLevelEnum::getInfo)
                .orElse("");
    }

    public static CredentialsLevelEnum of(Integer code) {
        Optional<CredentialsLevelEnum> first = Arrays.stream(CredentialsLevelEnum.values()).filter(v -> v.getCode().equals(code)).findFirst();
        return first.orElse(null);
    }
}
